home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-10-27 | 17.8 KB | 477 lines | [TEXT/KAHL] |
- // -----------------------------------------------------------------------------
- // File : demoWind.c
- // Date : October 14, 1994
- // Author : Jim Stout
- // Purpose : routines used for the demoCDEF Window
- //
- // -----------------------------------------------------------------------------
- #include "demoWind.h"
-
- #include "jimsCDEF.h"
- #include "dialogAssist.h"
-
- extern SysEnvRec gSysEnv;
- extern short gDemoType;
- extern ControlHandle gPopCtl, gPopCtl2, gPopCtl3, gBoxCtl,gRad1,gRad2;
- extern ControlHandle gProgBar1, gProgBar2, gProgBar3;
-
- MenuHandle hDynMenu;
-
- //=============================================================================
- // create new controls - called from doNewWindow() in demoShell.c
- //=============================================================================
- void doNewControls(WindowPtr theWindow)
- {
- Rect r;
- short ht;
-
- if(hDynMenu) {
- DeleteMenu(512);
- DisposeMenu(hDynMenu);
- }
- hDynMenu = 0;
-
- //-----------------------------------------------------------------------------
- // create the "Show:" popup menu control
- //-----------------------------------------------------------------------------
-
- SetRect(&r, 10, 6, 220, 26);
-
- gPopCtl = NewControl(theWindow, &r, "\pShow:", true,
- popupTitleRightJust, // right justified
- 132, // menu id
- popupInsetFrame+45, // ext varCode + title width
- 16*popUp+ctl3D, 0L);
-
- //-----------------------------------------------------------------------------
- // create the "Window color" popup menu control
- //-----------------------------------------------------------------------------
-
- SetRect(&r, 344, 4, 366, 26);
-
- gPopCtl2 = NewControl(theWindow, &r, "\p", true,
- popupTitleRightJust, // right justified
- 135, // menu id
- popupInsetFrame+
- popupIconOnly, // ext varCode + title width
- 16*popUp+ctl3D, 0L);
- //-----------------------------------------------------------------------------
- // create the "Window pattern" popup menu control
- //------------------------------------------------------------------ tCtlValue(gPopCtl3) -1; // get menu setting
-
- if(cInx)
- pixPat = GetPixPat(cInx+128);
-
- if(pixPat) {
- BackPixPat(pixPat);
- }
- else {
- BackPat(&qd.white);
- }
- if(redraw) {
- EraseRect(&theWindow->portRect);
- DrawControls(theWindow);
- }
-
- SetPort(savePort);
- }
-
- //=============================================================================
- // Handle a mouse click in a control
- //=============================================================================
- void doControlClick(ControlHandle theCtl, short thePart)
- {
-
- #pragma unused(thePart)
-
- switch(gDemoType) {
- case 1:
- if(theCtl == gRad1) {
- SetCtlValue(gRad1, 1);
- SetCtlValue(gRad2, 0);
- }
- else
- if(theCtl == gRad2) {
- SetCtlValue(gRad1, 0);
- SetCtlValue(gRad2, 1);
- }
- else // checkbox
- SetCtlValue(theCtl, !GetCtlValue(theCtl));
- break;
- }
- }
-
- //=============================================================================
- // Move the progress bar controls
- //=============================================================================
- void doProgress()
- {
- short val, max, min;
-
- // bump the value of the progress bars
-
- val = GetCtlValue(gProgBar1);
- max = GetCtlMax(gProgBar1);
- min = GetCtlMin(gProgBar1);
-
- if(val < max)
- SetCtlValue(gProgBar1, ++val);
- else
- SetCtlValue(gProgBar1, min);
-
- // make the "barber poles" rotate
-
- SetCtlValue(gProgBar2, !GetCtlValue(gProgBar2));
- SetCtlValue(gProgBar3, !GetCtlValue(gProgBar3));
- }
-
- //=============================================================================
- // create a couple of 3D control samples
- //=============================================================================
- void make3DControls(WindowPtr theWindow)
- {
- ControlHandle hCtl;
- Rect r;
- Str255 s,numStr;
- short inx,val=0;
- long num;
-
- //-----------------------------------------------------------------------------
- // create a couple of check boxes
- //-----------------------------------------------------------------------------
-
- SetRect(&r, 30, 73, 130, 89);
-
- for(inx=1;inx<3;inx++) {
- GetIndString(s, 129, 3);
- num = inx;
- NumToString(num, numStr);
- pStrCat((char *)s, (char *)numStr);
- hCtl = NewControl(theWindow, &r, s, true,
- val, // control value
- 0, // minimum value
- 1, // maximum value
- 16*0+checkBoxProc, 0L);
-
- OffsetRect(&r, 0, 26);
- val=1;
- }
-
- //-----------------------------------------------------------------------------
- // create a couple of radio buttons
- //-----------------------------------------------------------------------------
-
- SetRect(&r, 150, 73, 250, 89);
-
- for(inx=1;inx<3;inx++) {
- GetIndString(s, 129, 2);
- num = inx;
- NumToString(num, numStr);
- pStrCat((char *)s, (char *)numStr);
- hCtl = NewControl(theWindow, &r, s, true,
- val, // control value
- 0, // minimum value
- 1, // maximum value
- 16*button3D+radioButProc, 0L);
-
- OffsetRect(&r, 0, 26);
- val=0;
- if(inx==1)
- gRad1 = hCtl;
- else
- gRad2 = hCtl;
- }
-
- //-----------------------------------------------------------------------------
- // create some push buttons
- //-----------------------------------------------------------------------------
-
- SetRect(&r, 260, 43, 340, 63);
-
- hCtl = NewControl(theWindow, &r, "\pNormal", true,
- 0, // control value
- 0, // minimum value
- 1, // maximum value
- 16*button3D+pushButProc, 0L);
-
- OffsetRect(&r, 0, 30);
- hCtl = NewControl(theWindow, &r, "\pFixed Gray", true,
- 0, // control value
- 0, // minimum value
- 1, // maximum value
- 16*grayButton+pushButProc, 0L);
-
- OffsetRect(&r, 0, 30);
- hCtl = NewControl(theWindow, &r, "\pRect", true,
- 0, // control value
- 0, // minimum value
- 1, // maximum value
- 16*rectButton+pushButProc, 0L);
-
- OffsetRect(&r, 0, 30);
- hCtl = NewControl(theWindow, &r, "\pBack Color", true,
- 0, // control value
- 0, // minimum value
- 1, // maximum value
- 16*button3D+pushButProc+useWBG, 0L);
- }
-
- //=============================================================================
- // create some popup controls
- //=============================================================================
- void makePopupControls(WindowPtr theWindow)
- {
- ControlHandle theCtl;
- Rect r;
-
- //-----------------------------------------------------------------------------
- // create a popup controll for the large icon menu
- //-----------------------------------------------------------------------------
-
- SetRect(&r, 20, 40, 280, 94);
-
- theCtl = NewControl(theWindow, &r, "\pIcons:", true,
- popupTitleRightJust, // right justified
- 133, // menu id
- 70, // title width
- 16*popUp+ctl3D, 0L);
-
- //-----------------------------------------------------------------------------
- // create a menu dynamically and a popup control for it.
- //-----------------------------------------------------------------------------
-
- hDynMenu = NewMenu(512, "\pDynamic");
- if(hDynMenu) {
- AppendMenu(hDynMenu, "\pThis menu was");
- AppendMenu(hDynMenu, "\pcreated dynamically,");
- AppendMenu(hDynMenu, "\pnot read from a ");
- AppendMenu(hDynMenu, "\presource.");
- InsertMenu(hDynMenu, -1);
-
- SetRect(&r, 20, 104, 280, 123);
-
- theCtl = NewControl(theWindow, &r, "\pDynamic:", true,
- popupTitleRightJust, // right justified
- 512, // menu id
- 70, // title width
- 16*popUp, 0L);
- }
-
- //-----------------------------------------------------------------------------
- // create a menu with colored & styled text items
- //-----------------------------------------------------------------------------
- OffsetRect(&r, 0, 29);
- theCtl = NewControl(theWindow, &r, "\pColored:", true,
- popupTitleRightJust, // right justified
- 134, // menu id
- 70, // title width
- 16*popUp, 0L);
-
- //-----------------------------------------------------------------------------
- // create a "type in" style menu - draws symbol only
- //-----------------------------------------------------------------------------
-
- SetRect(&r, 290, 40, 315, 94);
-
- theCtl = NewControl(theWindow, &r, "\p", true,
- popupTitleRightJust, // right justified
- 303, // menu id
- popupSymbolOnly, // title width
- 16*popUp, 0L);
-
- //-----------------------------------------------------------------------------
- // create a "icon only" style menu - draws icons only
- //-----------------------------------------------------------------------------
-
- SetRect(&r, 290, 94, 330, 134);
-
- theCtl = NewControl(theWindow, &r, "\p", true,
- popupTitleRightJust, // right justified
- 304, // menu id
- popupIconOnly, // title width
- 16*popUp+popupFixedWidth, 0L);
-
- //-----------------------------------------------------------------------------
- // create a "popupCenterText" style menu - draws item text centered in ctl rect
- //-----------------------------------------------------------------------------
-
- SetRect(&r, 325, 40, 344, 94);
-
- theCtl = NewControl(theWindow, &r, "\p", true,
- popupTitleRightJust, // right justified
- 302, // menu id
- popupCenterText, // title width
- 16*popUp+useWFont, 0L);
- }
-
- //=============================================================================
- // create a small arrow control and a large 3D arrow control - both vertical
- // and horizontal variations.
- //=============================================================================
- void makeArrowControls(WindowPtr theWindow)
- {
- ControlHandle theCtl;
- Rect r;
-
- SetRect(&r, 60, 66, 177, 86);
-
- theCtl = NewControl(theWindow, &r, "\pNumber 1:", true,
- 0, // control value
- 0, // minimum value
- 10, // maximum value
- 16*spinner, 0L);
-
- SetRect(&r, 60, 94, 180, 121);
-
- theCtl = NewControl(theWindow, &r, "\pNumber 2:", true,
- 0, // control value
- -10, // minimum value
- 10, // maximum value
- 16*spinner+bigArrows+ctl3D,
- 0L);
-
- SetRect(&r, 200, 66, 325, 86);
-
- theCtl = NewControl(theWindow, &r, "\pNumber 3:", true,
- 0, // control value
- -10, // minimum value
- 10, // maximum value
- 16*spinner+horizArrows+ctl3D,
- 0L);
-
- SetRect(&r, 200, 94, 332, 121);
-
- theCtl = NewControl(theWindow, &r, "\pNumber 4:", true,
- 0, // control value
- -10, // minimum value
- 10, // maximum value
- 16*spinner+bigArrows+horizArrows,
- 0L);
- }
-
- //=============================================================================
- // create a default date control - has both date & time
- //=============================================================================
- void makeDateControls(WindowPtr theWindow)
- {
- ControlHandle theCtl;
- Rect r;
-
- SetRect(&r, 42, 55, 300, 75);
-
- theCtl = NewControl(theWindow, &r, "\pDate & Time:", true,
- 0, // ignored
- ctl3D, // 1 for 3D
- 0, // 1 for 24 hour time
- 16*dateTime, 0L);
-
- SetRect(&r, 90, 83, 300, 103);
-
- theCtl = NewControl(theWindow, &r, "\pDate:", true,
- 0, // ignored
- 0, // 1 for 3D
- 0, // 1 for 24 hour time
- 16*dateTime+dateOnly, 0L);
-
- SetRect(&r, 90, 111, 300, 131);
-
- theCtl = NewControl(theWindow, &r, "\pTime:", true,
- 0, // ignored
- 0, // 1 for 3D
- only24, // 1 for 24 hour time
- 16*dateTime+timeOnly, 0L);
- }
-
- //=============================================================================
- // create both vertical and horizontal 3D sliders
- //=============================================================================
- void makeSliderControls(WindowPtr theWindow)
- {
- ControlHandle theCtl;
- Rect r;
-
- SetRect(&r, 30, 43, 50+vWid, 43+7*vHt+21);
-
- theCtl = NewControl(theWindow, &r, "\p", true,
- 0, // control value
- 0, // minimum set by CDEF to 0
- 0, // maximum set by CDEF to 12*ticks
- 16*vSlider+ctl3D,
- 0L); // 7 ticks - range is 2-20
-
- OffsetRect(&r, 52, 0);
-
- theCtl = NewControl(theWindow, &r, "\p", true,
- 0, // control value
- 0, // minimum set by CDEF to 0
- 0, // maximum set by CDEF to 12*ticks
- 16*vSlider,
- 5L); // 5 ticks - range is 2-20
-
- OffsetRect(&r, 62, 0);
- r.right = r.left+16;
-
- theCtl = NewControl(theWindow, &r, "\p", true,
- 35, // control value
- 0, // minimum
- 100, // maximum
- 16*slider,
- 0L);
-
- SetRect(&r, 223, 43, 223+hWid, 63+hHt);
-
- theCtl = NewControl(theWindow, &r, "\p", true,
- 0, // control value
- 0, // minimum set by CDEF to 0
- 0, // maximum set by CDEF to 100
- 16*hSlider+ctl3D, 0L);
-
- OffsetRect(&r, 0, hHt+10);
-
- theCtl = NewControl(theWindow, &r, "\p", true,
- 0, // control value
- 0, // minimum set by CDEF to 0
- 0, // maximum set by CDEF to 100
- 16*hSlider, 0L);
-
- OffsetRect(&r, 0, hHt+20);
- r.bottom = r.top+16;
-
- theCtl = NewControl(theWindow, &r, "\p", true,
- 35, // control value
- 0, // minimum
- 100, // maximum
- 16*slider+4, 0L);
- }
-
- //=============================================================================
- // create a "normal" and "barber pole" progress bar (both horizontal)
- //=============================================================================
- void makeProgressControls(WindowPtr theWindow)
- {
- Rect r;
-
- SetRect(&r, 40, 68, 282, 82);
-
- gProgBar1 = NewControl(theWindow, &r, "\p", true,
- 10, // control value
- 0, // minimum value
- 240, // maximum value
- 16*progBar, 0L);
-
- OffsetRect(&r, 0, 40);
-
- gProgBar2 = NewControl(theWindow, &r, "\p", true,
- 1, // control value
- 0, // minimum value
- 1, // maximum value
- 16*progBar+barberPole, 0L);
-
- SetRect(&r, 315, 47, 333, 147);
-
- gProgBar3 = NewControl(theWindow, &r, "\p", true,
- 1, // control value
- 0, // minimum value
- 1, // maximum value
- 16*progBar+vertBar+roundBar+barberPole, 0L);
- }